package io.renren.utils;

import org.apache.commons.lang.WordUtils;

/**
 * 字符串处理
 *
 * @author: WangKun
 * @date: 2020/12/2
 */
public class TablesStringUtils {

    /**
     * 列名转换成Java属性名
     */
    public static String columnToJava(String columnName) {
        return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "");
    }

    /**
     * 表名转换成Java类名
     */
    public static String tableToJava(String tableName, String[] tablePrefixArray) {
        if (null != tablePrefixArray && tablePrefixArray.length > 0) {
            for (String tablePrefix : tablePrefixArray) {
                if (tableName.startsWith(tablePrefix)) {
                    tableName = tableName.replaceFirst(tablePrefix, "");
                }
            }
        }
        return columnToJava(tableName);
    }

    /**
     * 替换 转义符 \\.
     *
     * @param name
     * @return
     */
    public static String splitInnerName(String name) {
        name = name.replaceAll("\\.", "_");
        return name;
    }

    /**
     * 获取项目绝对路径
     */
    public static String getProjectPath() {
        return System.getProperty("user.dir").replace("\\", "/") + "/";
    }

    public static String getNullAble(String nullable) {
        if (("YES".equals(nullable)) || ("yes".equals(nullable)) || ("y".equals(nullable)) || ("Y".equals(nullable))) {
            return "Y";
        }
        if (("NO".equals(nullable)) || ("N".equals(nullable)) || ("no".equals(nullable)) || ("n".equals(nullable))) {
            return "N";
        }
        return null;
    }

}
